home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / MandelView.BackModule / part.c < prev    next >
Encoding:
Text File  |  1995-06-12  |  1.3 KB  |  60 lines

  1.  
  2. int newsteps( double x, double y)
  3. {
  4.     register double x1, y1, xs, ys ;
  5.     register int c;
  6.  
  7.     x1 = x ; y1 = y ;
  8.  
  9.     xs = x1 * x1 ;
  10.     ys = y1 * y1 ;
  11.     c = 0 ;
  12.     while( (xs + ys < 4.0) && (c < 255) ) {
  13.     y1 = 2 * x1 * y1 + y ;
  14.     x1 = xs - ys + x ;
  15.     c++ ;
  16.     xs = x1 * x1 ;
  17.     ys = y1 * y1 ;
  18.     }
  19.     return c ;
  20. }
  21.  
  22. int mandelbrot(parms0, parms1, maxiter )
  23.     double parms0,parms1;
  24.     int maxiter;
  25. {
  26.       register real x_re, x_im;
  27.       register real c_re, c_im;
  28.       register real xresq, ximsq;
  29.  
  30.       int count;
  31.  
  32.  
  33.       c_re = double_to_fixed(parms0);
  34.       c_im = double_to_fixed(parms1);
  35.       x_re = c_re ;
  36.       x_im = c_im ;
  37.  
  38.       /* The following loop is where the Real Work gets done. */
  39.       count=0;
  40.       while(count < 255)
  41.       {    
  42.     /* 
  43.       This is the familiar "z := z^2 + c; abort if |z| > 2"
  44.       Mandelbrot iteration, with the arithmetic operators hidden
  45.       in macros so that the same code can be compiled for either
  46.       fixed-point or floating-point arithmetic.
  47.       The macros (mul_real(), etc.) are defined in ms_real.h. 
  48.     */
  49.     xresq=mul_real(x_re, x_re);
  50.     ximsq=mul_real(x_im, x_im);
  51.     if(gteq_real(add_real(xresq, ximsq), four_real()))
  52.       break;
  53.     x_im=add_real(twice_mul_real(x_re, x_im), c_im);
  54.     x_re=add_real(sub_real(xresq, ximsq), c_re);
  55.     count++;
  56.       }
  57.   return count;
  58. }
  59.  
  60.